package com.gec.zhs.controller;

import com.gec.zhs.annotation.ZhsLogin;
import com.gec.zhs.component.RedisComponent;
import com.gec.zhs.entity.pojo.CategoryInfo;
import com.gec.zhs.entity.query.CategoryInfoQuery;
import com.gec.zhs.entity.vo.ResponseVO;
import com.gec.zhs.service.CategoryInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhs
 * @version 1.0
 * @date 2025-01-25
 * @description 视频分类
 */
@RestController
@RequestMapping("/category")
public class CategoryController extends ABaseController{

    @Autowired
    private CategoryInfoService categoryInfoService;

    @Autowired
    private RedisComponent redisComponent;

    @ApiOperation("获取影视分类")
    @RequestMapping("/loadAllCategory")
    @ZhsLogin(checkLogin = true)
    public ResponseVO getCategory(){
        List<CategoryInfo> categoryList = redisComponent.getCategoryList();
        return getSuccessResponseVO(categoryList);
    }

    @ApiOperation("新增/更新分类信息")
    @RequestMapping("/saveCategory")
    @ZhsLogin(checkLogin = true)
    public ResponseVO saveCategory(Integer pCategoryId,
                                   Integer categoryId,
                                   String categoryCode,
                                   String categoryName,
                                   String icon,
                                   String background){
        CategoryInfo categoryInfo = new CategoryInfo();
        categoryInfo.setPCategoryId(pCategoryId);
        categoryInfo.setCategoryId(categoryId);
        categoryInfo.setCategoryCode(categoryCode);
        categoryInfo.setCategoryName(categoryName);
        categoryInfo.setIcon(icon);
        categoryInfo.setBackground(background);

        categoryInfoService.saveCategoryInfo(categoryInfo);
        return getSuccessResponseVO(null);
    }

    @ApiOperation("删除分类")
    @RequestMapping("/delCategory")
    @ZhsLogin(checkLogin = true)
    public ResponseVO deleteCategory(Integer categoryId){
        categoryInfoService.delCategory(categoryId);
        return getSuccessResponseVO(null);
    }

    @ApiOperation("分类排序上下移动")
    @RequestMapping("changeSort")
    @ZhsLogin(checkLogin = true)
    public ResponseVO changeSort(Integer pCategoryId,String categoryIds){
        categoryInfoService.changeSort(pCategoryId, categoryIds);
        return getSuccessResponseVO(null);
    }
}
